package edu.pku.sei.modeler.uml.commands.sequence;

import edu.pku.sei.modeler.model.core.MetaModelElement;
import edu.pku.sei.modeler.model.structure.MetaNode;
import edu.pku.sei.modeler.model.uml.BasicInteractions.Interaction;
import edu.pku.sei.modeler.model.uml.Fragments.CombinedFragment;
import edu.pku.sei.modeler.uml.commands.NestedElementDeleteCommand;

public class UMLCombinedFragmentDeleteCommand extends
		NestedElementDeleteCommand {

	public UMLCombinedFragmentDeleteCommand(MetaNode node, MetaNode fatherNode,
			boolean isDeletedFromDiagram) {
		super(node, fatherNode, isDeletedFromDiagram);
	}

	@Override
	protected void deleteModelElement() {
		if (fatherNode.getModelElement() instanceof Interaction) {
			Interaction interaction = (Interaction) fatherNode.getModelElement();
			interaction.getFragment().remove(node.getModelElement());
		} else {
			CombinedFragment fragment = (CombinedFragment) fatherNode.getModelElement();
			fragment.getFragment().remove(node.getModelElement());
		}
	}

	@Override
	protected void undoDeleteModelElement() {
		MetaModelElement modelElement = this.node.getModelElement();
		if (fatherNode.getModelElement() instanceof CombinedFragment) {
			CombinedFragment fragment = (CombinedFragment) fatherNode.getModelElement();
			fragment.getFragment().add(modelElement);
		} else {
			Interaction interaction = (Interaction) fatherNode.getModelElement();
			interaction.getFragment().add(modelElement);
		}
	}

}
